package com.chanyachting.emall.serviceImpl;

import java.util.List;

import com.chanyachting.emall.dao.CompanymemberDAO;
import com.chanyachting.emall.domain.Company;
import com.chanyachting.emall.domain.Companymember;
import com.chanyachting.emall.domain.Member;
import com.chanyachting.emall.service.CompanyMemberService;

public class CompanyMemberServiceImpl implements CompanyMemberService {
	
	private CompanymemberDAO cmDao;

	public CompanyMemberServiceImpl() {
		
		this.cmDao=new CompanymemberDAO();
	}

	public boolean addCompanymember(Companymember cmember) {
		
		this.cmDao.save(cmember);
		
		return true;
	}

	public boolean delCompanymember(Companymember cmember) {
		
		this.cmDao.delete(cmember);
		
		return true;
	}

	public List<Companymember> getAllCompanymember() {
		
		return this.cmDao.find("from Companymember");
	}

	public List<Companymember> getCompanymemberByCompany(Company company) {
		
		return this.cmDao.getCompanymemberByCompany(company);
	}

	public Companymember getCompanymemberByMember(Member member) {
		
		return this.cmDao.getCompanymemberByMember(member);
	}

	public Companymember getOneCompanymember(Companymember cmember) {
		
		return (Companymember) this.cmDao.load(Companymember.class, cmember.getId());
	}

	public Company getCompanyByCompanymember(Companymember cmember) {
		
		String args []={String.valueOf(cmember.getCompanyId())};
		
		List<Company> list= this.cmDao.find("from Company where id=?", args);
		
		if(list!=null && list.size()>0) return (Company)list.get(0);
		
		return null;
	}

}
